package cn.edu.zbu.servlet;

import cn.edu.zbu.cn.edu.zbu.dao.CarDao;
import cn.edu.zbu.cn.edu.zbu.dao.CarDaoImpl;
import cn.edu.zbu.pojo.PageBean;
import cn.edu.zbu.pojo.Car;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "QueryPageServlet", value = "/QueryPageServlet")
public class QueryPageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int currentPage=Integer.parseInt(request.getParameter("currentPage"));
        int rows=Integer.parseInt(request.getParameter("rows"));
         //每页显示5条
        CarDao dao=new CarDaoImpl();
        List<Car> list=dao.findByCurrentpage(currentPage,rows);
        int totalCount=dao.findTotal();
        PageBean pb=new PageBean(currentPage,rows,totalCount,list);
        request.getSession().setAttribute("pb",pb);
        response.sendRedirect(request.getContextPath()+"/listpage.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
